/************************************************************************/
/* File to create a cube with two hexahedra                             */
/*                                                                      */
/* To generate the mesh do:                                             */
/*                                                                      */
/* gmsh -optimize_ho -format msh -"$dims"\                              */
/*      -o "$outFname" "$inFname" 1>/dev/null                           */
/*                                                                      */
/* - replace $dims with 3 (3D)                                          */
/* - replace $outFname with the desired output name (tens_mech_tut.msh) */
/* - replace $inFname with the name of this file (the one that you      */
/*   are reading)                                                       */
/************************************************************************/
/* LICENSE                                                   */
/* Copyright (C) 2018  broncodev                             */
/*                                                           */
/* This program is free software: you can redistribute it    */
/* and/or modify it under the terms of the GNU General       */
/* Public License as published by the Free Software          */
/* Foundation, either version 3 of the License, or (at your  */
/* option) any later version.                                */
/*                                                           */
/* This program is distributed in the hope that it will be   */
/* useful, but WITHOUT ANY WARRANTY; without even the        */
/* implied warranty of MERCHANTABILITY or FITNESS FOR A      */
/* PARTICULAR PURPOSE.  See the GNU General Public License   */
/* for more details.                                         */
/*                                                           */
/* You should have received a copy of the GNU General Public */
/* License along with this program.  If not, see             */
/* <http://www.gnu.org/licenses/>.                           */
/*************************************************************/

// Define parameters (lengths; optional)
// Set millimetres (1 mm = 1e-3 m)
side_len = DefineNumber[ 1e-3, Name "Parameters/bottomLength" ];

// Point tolerance
lc = side_len * 1e-3;

// Define the geometry (points and lines)
// A point is defined as {x, y, z, tolerance}
Point(1) = {0, 0, 0, lc};
Point(2) = {side_len, 0, 0, lc};
Point(3) = {side_len, side_len, 0, lc};
Point(4) = {0, side_len, 0, lc};

// A line is defined as {point0, point1}
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};

// Set the number of nodes per line (optional; useful for a
// nice mesh)
Transfinite Line {1, 2, 3, 4} = 1 Using Progression 1;

// Create a closed polygon with the lines
Line Loop(5) = {1, 2, 3, 4};

// Define a surface from the polygon
Plane Surface(6) = {5};

// Ask for quadrilaterals instead of triangles
Recombine Surface {6};

// // Create physical groups on the edges that can be used to
// // set boundaries (names are arbitrary).
// Physical Line("left") = {4};
// Physical Line("bottom") = {1};
// Physical Line("right") = {2};
// Physical Line("top") = {3};

// // Add a physical entity up to the dimension that you
// // require (Alex Lindsay)--name is arbitrary
// Physical Surface("surface") = {6};

//+
Physical Surface("bottom") = {6};
//+
Physical Surface("left") = {27};
//+
Physical Surface("right") = {19};
//+
Physical Surface("top") = {28};
//+
Physical Surface("front") = {23};
//+
Physical Surface("back") = {15};

// Extrude square to get cube
Extrude {0, 0, side_len} {
  Surface{6};
  // This creates two layers (two extruded elements)
  Layers{2};
  Recombine;
}

// Create physical groups on the edges that can be used to
// set boundaries (names are arbitrary).
//+
Physical Volume("cube_vol") = {1};
